import 'package:flutter/material.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Input',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: MyStatelessWidget(),
    );
  }
}

class MyStatelessWidget extends StatelessWidget {

  TextEditingController _pswController = new TextEditingController();


  @override
  Widget build(BuildContext context) {
    //解耦合，使用文本框监听
    _pswController.addListener((){
      print(_pswController.text);
    });

    return Scaffold(
      appBar: AppBar(
        title: Text("Input"),
      ),
      body: Column(
        children: <Widget>[
          TextField(
            autofocus: true,
            decoration: InputDecoration(
              labelText: "用户名",
              hintText: "请输入用户名",
              prefixIcon: Icon(Icons.assignment_ind)
            ),
            //键盘样式
            keyboardType: TextInputType.text,
            onChanged: (val){
              print(val);
            },
          ),
          TextField(
            autofocus: false,
            decoration: InputDecoration(
                labelText: "密码",
                hintText: "请输入密码",
                prefixIcon: Icon(Icons.remove_red_eye)
            ),
            //键盘样式
            keyboardType: TextInputType.text,
            //*号
            obscureText: true,
            controller: _pswController,
          )
        ],
      ),
    );
  }

}
